package com.mecuros.service.api.impl.service;

import cn.monitor4all.logRecord.annotation.OperationLog;
import com.mecuros.api.domain.SendRequest;
import com.mecuros.api.domain.SendResponse;
import com.mecuros.api.service.SendService;
import com.mecuros.common.vo.BasicResultVO;
import com.mecuros.service.api.impl.domain.SendTaskModel;
import com.mecuros.support.pipeline.ProcessContext;
import com.mecuros.support.pipeline.ProcessController;
import com.mecuros.support.pipeline.ProcessModel;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;

import java.util.Collections;

/**
 * @Classname SendServiceImpl
 * @Description
 * @Date 2022/5/14 12:54 下午
 * @Created by yujianbo
 */
@Slf4j
@Service
public class SendServiceImpl implements SendService {

    @Autowired
    private ProcessController processController;

    @Override
    @OperationLog(bizType = "SendService#batchSend", bizId = "#batchSendRequest.messageTemplateId", msg = "#batchSendRequest")
    public SendResponse send(SendRequest sendRequest) {
        SendTaskModel sendTaskModel = SendTaskModel.builder()
                .messageTemplateId(sendRequest.getMessageTemplateId())
                .messageParamList(Collections.singletonList(sendRequest.getMessageParam()))
                .build();
        ProcessContext<ProcessModel> context = ProcessContext.builder()
                .code(sendRequest.getCode())
                .processModel(sendTaskModel)
                .needBreak(false)
                .response(BasicResultVO.success())
                .build();

        ProcessContext process = processController.process(context);

        return new SendResponse(process.getResponse().getStatus(),process.getResponse().getMsg());
    }

    @Override
    public SendResponse batchSend(SendRequest sendRequest) {
        return null;
    }
}
